<template>
  <div class="warp-box">
    <el-row class="search-box" :gutter="10">
      <el-col :span="20">
        <el-input
          style="width:340px"
          v-model="parames.customerName"
          size="small"
          clearable
          placeholder="搜索客户名称"
        ></el-input>
        <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
        <el-button size="small" type="text" icon="el-icon-s-open" @click="handleSearch">高级搜索</el-button>
      </el-col>
    </el-row>
    <el-row class="main-box channel1234" style="margin:10px -5px;">
      <el-col :span="24">
        <!-- <el-button size="small" type="primary" icon="el-icon-plus" @click="handleAdd">新建客户</el-button> -->
      </el-col>
      <el-col :span="24">
        <el-table
          :data="tableData"
          border
          v-loading="loading"
          :row-class-name="tableRowClassName"
          style="margin-top:14px;"
        >
          <!-- <el-table-column
            show-overflow-tooltip
            width="200"
            fixed="left"
            prop="contractProductId"
            label="合同编号"
          ></el-table-column> -->
          <el-table-column show-overflow-tooltip prop="customerName" label="客户名称"></el-table-column>
          <el-table-column prop="serviceAmount" label="服务金额"></el-table-column>
          <el-table-column prop="receiptedAmount" label="总实收"></el-table-column>
          <el-table-column prop="expenditureAmount" label="总支出"></el-table-column>
          <el-table-column prop="currentReceiptedAmount" label="当期实收"></el-table-column>
          <el-table-column prop="currentExpenditureAmount" label="当期支出"></el-table-column>
          <el-table-column prop="seller" width="200" label="计提人">
            <template slot-scope="scope">
              <div>{{scope.row.seller}}(工号：{{scope.row.sellerWorkNumber}})</div>
            </template>
          </el-table-column>
          <el-table-column prop="sellerDepartment" label="计提人部门"></el-table-column>
          <el-table-column prop="position" label="工作职责"></el-table-column>
          <el-table-column width="120" align="center" label="操作" fixed="right" v-if="qiandanBtn">
            <template slot-scope="scope">
              <el-button size="mini" type="primary" @click="handleSend(scope.row)">提交绩效</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-col>
      <el-col :span="24">
        <pages :parames="parames" @render="checkPage"></pages>
      </el-col>
    </el-row>
    <amountDialog :mountData="mountData" @checkRender="getList"></amountDialog>
    <searchDialog :searchData="searchData" @checkSearch="checkSearch" @resetSearch="resetSearch"></searchDialog>

  </div>
</template>

<script>
import amountDialog from './addAmountDialog'
import searchDialog from "./qiandanSearch.vue"; //高级搜索弹窗

export default {
  data() {
    return {
      loading: false,
      parames: {
        page: 1, //页码index
        limit: 10, //页码最大
        customerName: '', //联系人名称
        totalCount: 0,
        search: []
      },
      searchData: {
        //搜索弹窗
        show: false
      },
      mountData: {
        contractProductId: '',
        show: false
      },
      tableData: [],
      qiandanBtn: false
    };
  },
  components: {
    amountDialog,
    searchDialog
  },
  methods: {
    search() {
      //查询
      this.parames.page = 1;
      let searchDate = this.parames.search
      let n = 0
      this.parames.search.forEach(el=>{
        if (el.key == 'customerName') {
          n = 1
        }
      })
      if (this.parames.customerName && n == 0) {
        this.parames.search.push({
          key: 'customerName',
          value: this.parames.customerName,
          type: 'string'
        })
      } else if (this.parames.customerName && n == 1) {
        this.parames.search.forEach((el,index)=>{
          if (el.key == 'customerName') {
            el.value = this.parames.customerName
          }
        })
      } else if (!this.parames.customerName && n == 1) {
        this.parames.search.forEach((el,index)=>{
          if (el.key == 'customerName') {
            this.parames.search.splice(index,1)
          }
        })
      }
      this.getList()
    },
    handleSearch() {
      //打开高级搜索弹窗
      this.searchData.customerName = this.parames.customerName
      this.searchData.show = true;
    },
    resetSearch () {
      this.parames.customerName = ''
    },
    checkSearch (value) {
      this.parames.search = value
      value.forEach(el=>{
        if(el.key == 'customerName') {
          this.parames.customerName = el.value
        }
      })
      this.parames.page = 1
      this.getList()
    },
    checkPage () {
      this.getList()
    },
    handleSetTitle () { //设置表头列
      this.titleData.show = true
    },
    handleSend (row) {//提交签单绩效
      this.mountData.type = 'qiandan'
      this.mountData.contractProductId = row.contractProductId
      this.mountData.show = true
    },
    getList() {//获取页面数据
      this.loading = true
      this.$post(this.$api.postPerformanceListSigningVerification,this.parames).then(response => {
        if (response.data.succeed) {
          this.parames.totalCount = response.data.totalCount
          this.tableData = response.data.data
        }
        setTimeout(() => {
          this.loading = false
        }, 200);
      })
    },
    tableRowClassName({ row, rowIndex }) {
      //斑马表格
      if (rowIndex % 2 === 1) {
        return "warning-row";
      } else {
        return "success-row";
      }
      return "";
    }
  },
  mounted() {
    let buttonLimit = this.$utils.getLocalStorage('buttonlist')  //按钮缓存
    if (buttonLimit.indexOf('k062') !== -1) {
      this.qiandanBtn = true
    }
    this.getList()
  }
};
</script>

<style>
.el-table .warning-row {
  background: #f9f9f9;
}
.el-table .success-row {
  background: #fff;
}
</style>